package SmartHome.devices;

import SmartHome.observers.Subject;
import SmartHome.states.DeviceState;
import SmartHome.states.OffState;
import SmartHome.states.OnState;
import SmartHome.strategys.DeviceStrategy;
import SmartHome.strategys.EnergySavingStrategy;

public class AirConditioner extends SmartDevice {
    public AirConditioner() {
        super();
    }

    public AirConditioner(DeviceState state, DeviceStrategy strategy) {
        super(state, strategy);
    }

    @Override
    public void turnOn() {
        System.out.println("空调打开");
        strategy.execute();
        setState(new OnState());
    }

    @Override
    public void turnOff() {
        System.out.println("空调关闭");
        setState(new OffState());
    }

    @Override
    public void powerOn() {
        System.out.println("空调电源开启");
    }

    @Override
    public void update(Subject subject, String message) {
        if(message.contains("温度下降")){
            System.out.println("空调收到消息: " + message);
            setStrategy(new EnergySavingStrategy());
            //System.out.println("空调策略切换为: " + strategy.getClass().getSimpleName());
        }
    }
}
